<template>
  <div class="pro-cont">
    <el-table :data="proList" style="width: 100%">
      <el-table-column label="角色ID">
        <template #default="scope">
          {{ scope.row.objectId }}
        </template>
      </el-table-column>
      <el-table-column label="商品名称">
        <template #default="scope">
          {{ scope.row.proname }}
        </template>
      </el-table-column>
      <el-table-column label="商品图片">
        <template #default="scope">
          <img :src="scope.row.img1" style="height: 30px" alt="" srcset="" />
        </template>
      </el-table-column>
      <el-table-column
        label="分类"
        :filters="[
          { text: '手机', value: '手机' },
          { text: '家电', value: '家电' },
          { text: '汽车', value: '汽车' },
          { text: '图书', value: '图书' },
        ]"
        :filter-method="filterHandler"
      >
        <template #default="scope">
          {{ scope.row.category }}
        </template>
      </el-table-column>
      <el-table-column label="价格" sortable prop="originprice">
        <template #default="scope">
          {{ scope.row.originprice }}
        </template>
      </el-table-column>
      <el-table-column label="折扣" sortable prop="discount">
        <template #default="scope">
          {{ scope.row.discount }}
        </template>
      </el-table-column>
      <el-table-column label="销量" sortable prop="sales">
        <template #default="scope">
          {{ scope.row.sales }}
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template #default="scope">
          <el-button size="small" @click="handleEdit(scope.$index, scope.row)"
            >编辑</el-button
          >
          <el-button
            size="small"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { proGet } from "../../api/product";
export default {
  data() {
    return {
      proList: [],
    };
  },
  created() {
    proGet().then((res) => {
      this.proList = res.data.results;
    });
  },
  methods: {
    // 这个filterHandler方法会在确定筛选条件后，去对每一行数据进行对比
    filterHandler(value, row) {
      console.log(value); //value是我选中的想看到的分类
      return row.category == value; // 此处return为true的数据将被保留在筛选结果中
    },
  },
};
</script>

<style scoped>
.pro-cont {
  height: 80vh;
  overflow-y: scroll;
}
</style>
